import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:sports_new/controller/service/resource_service.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/resources/styles.dart';
import 'package:sports_new/server/api/other_api.dart';
import 'package:sports_new/utils/image_utils.dart';
import 'package:sports_new/utils/routes.dart';
import 'package:sports_new/utils/toast_utils.dart';
import 'package:sports_new/utils/user.dart';
import 'package:sports_new/utils/utils.dart';
import 'package:sports_new/view/my/expert/expert_contact_code.dart';
import 'package:sports_new/widgets/base/qkd_image.dart';

import '../../../widgets/base/qkd_text.dart';

class MyExpertApplyTypePage extends StatelessWidget {
  MyExpertApplyTypePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Styles.appBar(title: QkdText('入驻中心')),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            children: [
              GestureDetector(
                onTap: () {
                  User.needLogin(() async {
                    Utils.onEvent("expert_joinin_now",params: {"type": "个人"});
                    final data = await OtherApi.expertApplyInfo();
                    if (data == null) {
                      Get.toNamed(Routes.expertApply);
                    } else {
                      Get.toNamed(Routes.expertApplySuccess, arguments: data);
                    }
                  });
                },
                child: _buildCard(0),
              ),
              Container(height: 16),
              GestureDetector(
                onTap: () {
                  Utils.onEvent("expert_joinin_now",params: {"type": "企业"});
                  Get.to(() => servicePage("企业/网媒入驻"));
                },
                child: _buildCard(1),
              ),
              Container(height: 16),
              GestureDetector(
                onTap: () {
                  Utils.onEvent("expert_joinin_now",params: {"type": "MCN"});
                  Get.to(() => servicePage("MCN机构入驻"));
                },
                child: _buildCard(2),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildCard(int index) {
    String title = '';
    String content = '';
    String image = '';
    Color color = Colours.white;
    if (index == 0) {
      title = '个人入驻';
      content = '适合熟悉足球、篮球的个人申请成为作者和球迷分享比赛的理解以及赛果预测。';
      image = 'expert_apply_red.png';
      color = Colours.main;
    } else if (index == 1) {
      title = '企业/网媒';
      content = '适合报纸、杂志、电视、电台或企业公司等分支机构相关品牌、产品和服务。';
      image = 'expert_apply_red.png';
      color = Colours.main;
    } else if (index == 2) {
      title = 'MCN机构';
      content = '适合MCN机构，拥有行业知名账户以及拥有体育行业超强影响力机构入驻。';
      image = 'expert_apply_red.png';
      color = Colours.main;
    }
    return Container(
      padding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          image: DecorationImage(
              image: AssetImage(Utils.getImgPath(image)), fit: BoxFit.fill)),
      child: Column(
        // crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          QkdText(title,
            fontSize: 18,
            fontWeight: FontWeight.w500,
            color: Colours.white
          ),
          Container(height: 8),
          QkdText(
            content,
            color: Colours.white,
            textAlign: TextAlign.center,
          ).paddingSymmetric(horizontal: 8),
          Container(height: 12),
          Container(
            padding:
                const EdgeInsets.symmetric(horizontal: 12, vertical: 4.5),
            decoration: BoxDecoration(
                color: Colours.white, borderRadius: BorderRadius.circular(4)),
            child: QkdText('立即申请', fontWeight: FontWeight.w500, color: color)
          )
        ],
      ),
    );
  }

  Widget servicePage(String title) {
    final resource = Get.find<ResourceService>();
    return Scaffold(
      appBar: Styles.appBar(title: QkdText(title)),
      backgroundColor: Colours.greyF7F7F7,
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                width: Get.width,
                padding: const EdgeInsets.symmetric(vertical: 30),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colours.main),
                child: const Column(
                  // crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    QkdText("目前该渠道仅限平台邀请加入，",color: Colours.white),
                    QkdText("如有疑问请咨询球客岛客服。",color: Colours.white)
                  ],
                ),
              ),
              Container(height: 16),
              Container(
                width: Get.width,
                padding: const EdgeInsets.only(top: 30, bottom: 40),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colours.white),
                child: const ExpertContactCode(),
              )
            ],
          ),
        ),
      ),
    );
  }
}
